package com.simple.database.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("test")
@Controller
public class TestController {

	@InitBinder
	public 	void InitBinder(WebDataBinder binder){
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		CustomDateEditor dateEditor = new CustomDateEditor(df, true);
		binder.registerCustomEditor(Date.class,dateEditor);
	}
	
	@RequestMapping(value="/param",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> getFormatData(Date date) throws ParseException{
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("name", "zhangsan");
		map.put("age", 22);
//		String format = new SimpleDateFormat("yyyy-MM HH:mm").format(date);
		map.put("date",date);
		return map;
	}
}
